home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / faxd / faxServerApp.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  6KB  |  178 lines

  1. /*    $Header: /usr/people/sam/fax/faxd/RCS/faxServerApp.h,v 1.51 1994/03/02 15:09:47 sam Rel $ */
  2. /*
  3.  * Copyright (c) 1990, 1991, 1992, 1993, 1994 Sam Leffler
  4.  * Copyright (c) 1991, 1992, 1993, 1994 Silicon Graphics, Inc.
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and 
  7.  * its documentation for any purpose is hereby granted without fee, provided
  8.  * that (i) the above copyright notices and this permission notice appear in
  9.  * all copies of the software and related documentation, and (ii) the names of
  10.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  11.  * publicity relating to the software without the specific, prior written
  12.  * permission of Sam Leffler and Silicon Graphics.
  13.  * 
  14.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  15.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  16.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  17.  * 
  18.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  19.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  20.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  22.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  23.  * OF THIS SOFTWARE.
  24.  */
  25. #ifndef _faxServerApp_
  26. #define    _faxServerApp_
  27. /*
  28.  * Fax Queue Manager and Command Handler.
  29.  */
  30. #include <stdarg.h>
  31. #include <Dispatch/iohandler.h>
  32. #include "Str.h"
  33.  
  34. class FaxServer;
  35. class FaxRequest;
  36. class FaxMachineInfo;
  37. class FaxRecvInfo;
  38. class TIFF;
  39.  
  40. typedef unsigned int JobStatus;
  41.  
  42. /*
  43.  * Jobs represent send requests in the queue.
  44.  */
  45. struct Job {
  46.     enum {
  47.     no_status    = 0,
  48.     done        = 1,
  49.     requeued    = 2,
  50.     removed        = 3,
  51.     timedout    = 4,
  52.     no_formatter    = 5,
  53.     format_failed    = 6,
  54.     poll_rejected    = 7,
  55.     poll_no_document= 8,
  56.     poll_failed    = 9,
  57.     file_rejected    = 10,
  58.     killed        = 11,
  59.     };
  60.     Job*    next;        // linked list
  61.     fxStr    file;        // queue file name
  62.     time_t    tts;        // time to send job
  63.     int        pri;        // priority
  64.  
  65.     Job(const fxStr& s, time_t t) : file(s) { tts = t; pri = 0; }
  66.     Job(const Job& j) : file(j.file) { tts = j.tts; pri = 0; }
  67.     Job(const Job* j) : file(j->file) { tts = j->tts; pri = 0; }
  68.     ~Job() {}
  69. };
  70.  
  71. /*
  72.  * This class represents a thread of control that manages the
  73.  * send queue, deals with system-related notification (sends
  74.  * complete, facsimile received, errors), and delivers external
  75.  * commands passed in through the command FIFOs.  This class is
  76.  * also responsible for preparing documents for sending by
  77.  * doing formatting tasks such as converting PostScript to TIFF.
  78.  *
  79.  * In a multi-threaded environment, this class represents a
  80.  * separate thread of control.
  81.  */
  82. class faxServerApp : public IOHandler {
  83. private:
  84.     fxStr    appName;        // program name
  85.     fxStr    device;            // modem device
  86.     fxStr    devID;            // mangled device name
  87.     fxStr    queueDir;        // spooling directory
  88.     fxStr    serverPID;        // pid of this process
  89.     FaxServer*    server;            // active server app
  90.     Job*    queue;            // job queue
  91.     fxBool    use2D;            // ok to generate 2D-encoded facsimile
  92.     fxBool    running;        // server running
  93.     int        requeueInterval;    // time between job retries
  94.     u_long    currentTimeout;        // time associated with timer
  95.     time_t    jobStart;        // starting time for job
  96.     time_t    fileStart;        // starting time for file/poll
  97.     int        fifo;            // fifo job queue interface
  98.     int        devfifo;        // fifo device interface
  99.     FaxRequest*    curreq;            // current job being processed
  100.  
  101.     static const fxStr fifoName;
  102.     static const fxStr sendDir;
  103.     static const fxStr recvDir;
  104.     static const fxStr notifyCmd;
  105.     static const fxStr faxRcvdCmd;
  106.     static const fxStr pollRcvdCmd;
  107.     static const fxStr ps2faxCmd;
  108.  
  109. // miscellaneous stuff
  110.     void    detachFromTTY();
  111.     void    setRealIDs();
  112.     void    logError(const char* fmt ...);
  113.     void    vlogError(const char* fmt, va_list ap);
  114.     void    traceServer(const char* fmt ...);
  115.     void    traceQueue(const char* fmt ...);
  116.     void    traceAtJobs(const char* fmt ...);
  117.     const char*    fmtTime(time_t);
  118.     void    recordRecv(const FaxRecvInfo& ri);
  119.     void    account(const char* cmd, const struct FaxAcctInfo&);
  120.     void    runCmd(const char* cmd, fxBool changeIDs = FALSE);
  121.     time_t    requeueTTS(time_t now) const;
  122.  
  123.     static struct popenRecord* popenList;
  124.     FILE*    popen(const char* cmd, const char* mode);
  125.     int        pclose(FILE*);
  126. // FIFO-related stuff
  127.     int        openFIFO(const char* fifoName, int mode,
  128.             fxBool okToExist = FALSE);
  129.     void    fifoMessage(const char* mesage);
  130. // job management interfaces
  131.     void    processJob(Job* job);
  132.     void    processJob1(Job*, FaxRequest* req);
  133.     void    sendJob(FaxRequest* req, FaxMachineInfo&);
  134.     void    requestComplete(FaxRequest* req, fxBool notify);
  135.     void    insertJob(Job* job);
  136.     void    deleteJob(const fxStr& name);
  137.     Job*    removeJob(const fxStr& name);
  138.     fxBool    alterJob(const char* s);
  139. // job preparation stuff
  140.     void    scanQueueDirectory();
  141.     void    scanJobQueue();
  142.     void    startTimer(u_long sec);
  143.     void    stopTimer();
  144.     FaxRequest*    readQFile(const fxStr& filename, int fd);
  145.     void    deleteRequest(JobStatus why, FaxRequest* req,
  146.             fxBool force = FALSE);
  147.     void    notifySender(JobStatus why, FaxRequest& req);
  148.     JobStatus    convertPostScript(const fxStr& inFile, const fxStr& outFile,
  149.             FaxRequest& req, const FaxMachineInfo& info);
  150.     JobStatus    checkFileFormat(const fxStr& file, const FaxMachineInfo& info,
  151.             fxStr& emsg);
  152.     fxBool    checkPageFormat(TIFF*, const FaxMachineInfo& info, fxStr& emsg);
  153. public:
  154.     faxServerApp();
  155.     ~faxServerApp();
  156.  
  157.     void    initialize(int argc, char** argv);
  158.     void    open();
  159.     void    close();
  160.  
  161.     fxBool    isRunning() const;
  162. // Dispatcher hooks
  163.     int        inputReady(int);
  164.     void    timerExpired(long sec, long usec);
  165. // notification interfaces used by FaxServer
  166.     void    notifyModemReady();
  167.     void    notifyDocumentSent(FaxRequest&, u_int fileIndex);
  168.     void    notifyPollRecvd(FaxRequest&, const FaxRecvInfo&);
  169.     void    notifyPollDone(FaxRequest&, u_int pollIndex);
  170.     void    notifySendDone(FaxRequest* req, u_int npages,
  171.             const char* csi, u_int sigrate, const char* df);
  172.     void    notifyRecvDone(const FaxRecvInfo& req);
  173. // system logging interfaces used by FaxServer
  174.     void    vlogInfo(const char* fmt, va_list ap);
  175. };
  176. inline fxBool faxServerApp::isRunning() const { return running; }
  177. #endif
  178.